function LoginPage() {
    const [loginId, setLoginId] = React.useState('18911482563'); // 设置默认账号
    const [password, setPassword] = React.useState('');
    const [error, setError] = React.useState('');
    const [loading, setLoading] = React.useState(false);

    const onSubmit = async (e) => {
        e.preventDefault();
        setError('');
        if (!loginId || !password) {
            setError('请输入账号和密码');
            return;
        }
        setLoading(true);

        try {
            const response = await fetch(Utils.getApiUrl('/chm/api/auth/login'), {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                mode: 'cors',
                credentials: 'omit',
                body: JSON.stringify({
                    loginId: loginId,
                    password: password
                })
            });

            const result = await response.json();

            if (result.status === 0) {
                // 登录成功
                try {
                    localStorage.setItem('auth.loggedIn', 'true');
                    localStorage.setItem('auth.token', result.data.token);
                    localStorage.setItem('auth.userId', result.data.userId);
                    localStorage.setItem('auth.username', result.data.username);
                    localStorage.setItem('auth.realName', result.data.realName);
                    localStorage.setItem('auth.email', result.data.email);
                } catch (e) {
                    console.error('保存登录信息失败:', e);
                }
                window.location.replace('index.html');
            } else {
                setError(result.msg || '登录失败');
            }
        } catch (error) {
            setError('网络错误，请检查网络连接');
            console.error('登录请求失败:', error);
        } finally {
            setLoading(false);
        }
    };

    return (
        React.createElement('div', { className: 'auth-container' },
            React.createElement('div', { className: 'auth-header' },
                React.createElement('h1', null, '系统登录'),
                React.createElement('p', null, '请输入账号和密码进入系统')
            ),

            error && React.createElement('div', { className: 'message error' }, error),

            React.createElement('form', { onSubmit },
                React.createElement('div', { className: 'form-group' },
                    React.createElement('label', { htmlFor: 'account' }, '账号'),
                    React.createElement('input', {
                        type: 'text',
                        id: 'account',
                        value: loginId,
                        onChange: (e) => setLoginId(e.target.value),
                        placeholder: '18911482563'
                    })
                ),

                React.createElement('div', { className: 'form-group' },
                    React.createElement('label', { htmlFor: 'password' }, '密码'),
                    React.createElement('input', {
                        type: 'password',
                        id: 'password',
                        value: password,
                        onChange: (e) => setPassword(e.target.value),
                        placeholder: '请输入密码'
                    })
                ),

                React.createElement('button', {
                    type: 'submit',
                    disabled: loading,
                    className: 'auth-btn'
                }, loading ? '登录中...' : '登录'),

                React.createElement('div', { className: 'auth-link', style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' } },
                    React.createElement('a', {
                        href: 'forgot-password.html'
                    }, '忘记密码？'),
                    React.createElement('a', {
                        href: 'change-password.html'
                    }, '修改密码')
                )
            )
        )
    );
}

ReactDOM.render(React.createElement(LoginPage), document.getElementById('root'));


